# -*- coding:utf-8 -*-
# @Time:2024/4/1921:01
# @Author:miuzg
# @FileName:new test2.py
# @Software:PyCharm
import requests
from multiprocessing import  Process
from user_agent import generate_user_agent


def work(url,headers):
    for i in range(100):
        res = requests.get(url,headers=headers)
        print(res)
        if '猫眼验证中心' in res.text:
            print('被反爬了')
            with open('猫眼反爬.html','w',encoding='utf-8') as f:
                f.write(res.text)
        else:
            print('没被反爬')


if __name__ == '__main__':
    url = 'https://www.maoyan.com/'
    headers = {
        'User-Agent': generate_user_agent()
    }
    #创建多个线程
    process = [Process(target=work,args=(url,headers)) for i in range(5)]

    #启动
    for p in process:
        p.start()

    # 阻塞
    for p in process:
        p.join()